package com.acando.mate.view;

import java.util.ArrayList;

import com.acando.mate.PlacesAdapter;
import com.acando.mate.R;
import com.acando.mate.WorkersAdapter;
import com.acando.mate.business.PlacesProvider;
import com.acando.mate.models.Worker;

import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class PlacesFragment extends Fragment{

	private View mSelectedView;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View v = inflater.inflate(R.layout.places_fragment, container, false);

		// Retrieving the currently selected item number
		int position = getArguments().getInt("position");

		// List of rivers
		String[] menus = getResources().getStringArray(R.array.menus);

		// Updating the action bar title
		getActivity().getActionBar().setTitle(menus[position]);

		// Initializing and loading url in webview
		ListView listView = (ListView) v.findViewById(R.id.placesListView);
		PlacesAdapter placesAdapter = new PlacesAdapter(getActivity(),
				PlacesProvider.getPlaces(getActivity()));
		
		 
		
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View v,
					int position, long id) {
				Log.d("asd", "" + v.getId());
				LinearLayout view = (LinearLayout) v
						.findViewById(R.id.workers_details_layout);
				if (view.equals(mSelectedView)) {
					mSelectedView = null;
					view.setVisibility(View.GONE);
				} else {
					if (mSelectedView != null) {
						mSelectedView.setVisibility(View.GONE);
					}
					mSelectedView = view;
					view.setVisibility(View.VISIBLE);
				}
			}
		});
		listView.setAdapter(placesAdapter);

		return v;
	}
	
	
}
